package cn.dgut.training.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.client.RestTemplate;

public class Code2Session {
    public static JSONObject getCode2SessionJsonObj(String appId, String appSecret, String code) {
        String code2Session = String.format("https://api.weixin.qq.com/sns/jscode2session" +
                "?appid=%s" +
                "&secret=%s" +
                "&js_code=%s" +
                "&grant_type=authorization_code", appId, appSecret, code);

        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.getForObject(code2Session, String.class);

        return JSON.parseObject(result);
    }
}
